XML Syntax | 您所在的位置:网站首页 › xml interpretation grammar › XML Syntax |
XML Syntax Rules
❮ Previous
Next ❯
The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use. XML Documents Must Have a Root ElementXML documents must contain one root element that is the parent of all other elements: .....In this example is the root element: Tove Jani Reminder Don't forget me this weekend! The XML PrologThis line is called the XML prolog: The XML prolog is optional. If it exists, it must come first in the document. XML documents can contain international characters, like Norwegian 酶忙氓 or French 锚猫茅. To avoid errors, you should specify the encoding used, or save your XML files as UTF-8. UTF-8 is the default character encoding for XML documents. Character encoding can be studied in our Character Set Tutorial. UTF-8 is also the default encoding for HTML5, CSS, JavaScript, PHP, and SQL. All XML Elements Must Have a Closing TagIn XML, it is illegal to omit the closing tag. All elements must have a closing tag: This is a paragraph. Note: The XML prolog does not have a closing tag! This is not an error. The prolog is not a part of the XML document. XML Tags are Case SensitiveXML tags are case sensitive. The tag is different from the tag . Opening and closing tags must be written with the same case: This is correct"Opening and closing tags" are often referred to as "Start and end tags". Use whatever you prefer. It is exactly the same thing. XML Elements Must be Properly NestedIn HTML, you might see improperly nested elements: This text is bold and italicIn XML, all elements must be properly nested within each other: This text is bold and italicIn the example above, "Properly nested" simply means that since the element is opened inside the element, it must be closed inside the element. XML Attribute Values Must Always be QuotedXML elements can have attributes in name/value pairs just like in HTML. In XML, the attribute values must always be quoted: Tove Jani Entity ReferencesSome characters have a special meaning in XML. If you place a character like " with ; as well. Comments in XMLThe syntax for writing comments in XML is similar to that of HTML: Two dashes in the middle of a comment are not allowed: White-space is Preserved in XMLXML does not truncate multiple white-spaces (HTML truncates multiple white-spaces to one single white-space): XML: Hello Tove HTML: Hello Tove XML Stores New Line as LFWindows applications store a new line as: carriage return and line feed (CR+LF). Unix and Mac OSX use LF. Old Mac systems use CR. XML stores a new line as LF. Well Formed XMLXML documents that conform to the syntax rules above are said to be "Well Formed" XML documents. ❮ Previous Next ❯ ★ +1 W3schools Pathfinder Track your progress - it's free! Log in Sign Up |
CopyRight 2018-2019 实验室设备网 版权所有 |